package com.diandian.backend.store.controller;

import com.diandian.backend.store.param.*;
import com.diandian.backend.store.resp.StoreDouyinLifeStoreInfoDetailResp;
import com.diandian.backend.store.service.StoreDouyinLifeStoreInfoOpenApiService;
import com.diandian.base.boot.starter.response.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * [门店]抖音本地生活门店-对外开放接口API
 */
@RestController
@RequestMapping("/douyin/life/store/info/open/api")
public class DouyinLifeStoreInfoOpenApiController {

    @Autowired
    private StoreDouyinLifeStoreInfoOpenApiService storeDouyinLifeStoreInfoOpenApiService;

    /**
     * 根据线上门店编码或线下门店编码查询门店信息
     */
    @PostMapping("/detail/code")
    public BaseResult getDetailByCode(@RequestBody StoreDouyinLifeStoreInfoDetailByCodeParam param) {
        param.check();
        StoreDouyinLifeStoreInfoDetailResp resp = storeDouyinLifeStoreInfoOpenApiService.getDetailByCode(param);
        return (resp == null) ? new BaseResult(1, "未查询到门店信息", null) : new BaseResult(0, "success", resp);
    }

    /**
     * 根据直播间ID查询门店信息
     */
    @PostMapping("/detail/roomId")
    public BaseResult getDetailByRoomId(@RequestBody StoreDouyinLifeStoreInfoDetailByRoomIdParam param) {
        param.check();
        StoreDouyinLifeStoreInfoDetailResp resp = storeDouyinLifeStoreInfoOpenApiService.getDetailByRoomId(param);
        return (resp == null) ? new BaseResult(1, "未查询到门店信息", null) : new BaseResult(0, "success", resp);
    }

    /**
     * 获取门店信息列表
     * @param param
     * @return
     */
    @PostMapping("/list")
    public BaseResult list(@RequestBody StoreDouyinLifeStoreInfoListParam param) {
        param.check();
        return new BaseResult(0, "success", storeDouyinLifeStoreInfoOpenApiService.getList(param.toDTO()));
    }

}